﻿@namespace MudBlazor
@inherits MudComponentBase
@typeparam T

<li @attributes="UserAttributes" class="@Classname" style="@Style">
    <div class="@ContentClassname" @onclick="OnItemClicked" @onclick:stopPropagation="true">
        @if (Content != null)
        {
            @Content
        }
        else
        {
            <MudTreeViewItemToggleButton Loading="Loading" Expanded="Expanded" ExpandedChanged="OnItemExpanded" Visible="@HasChild" ExpandedIcon="@ExpandedIcon" ExpandedIconColor="@ExpandedIconColor" LoadingIcon="@LoadingIcon" LoadingIconColor="LoadingIconColor"></MudTreeViewItemToggleButton>

            @if (MudTreeRoot != null && MudTreeRoot.MultiSelection)
            {
                <MudCheckBox Class="mud-treeview-item-checkbox" Color="Color.Inherit" CheckedIcon="@CheckedIcon" UncheckedIcon="@UncheckedIcon" @bind-Checked="IsChecked" Disabled="@Disabled"></MudCheckBox> 
            }

            @if (!string.IsNullOrEmpty(Icon))
            {
                <div class="mud-treeview-item-icon">
                    <MudIcon Icon="@Icon" Color="@IconColor" />
                </div>
            }
            
            <MudText Typo="@TextTypo" Class="@TextClassname">
                @Text
            </MudText>  

            @if (!string.IsNullOrEmpty(EndText))
            {            
                <MudText Typo="@EndTextTypo" Class="@EndTextClass">
                    @EndText
                </MudText>  
            }

            @if (!string.IsNullOrEmpty(EndIcon))
            {
                <div class="mud-treeview-item-icon">
                    <MudIcon Icon="@EndIcon" Color="@EndIconColor" />
                </div>
            }
        }
    </div>
    @if (HasChild)
    {
        <MudCollapse Expanded="@Expanded">
            <CascadingValue Value="@MudTreeRoot" IsFixed="true">
                <CascadingValue Value="this" IsFixed="true">
                    <MudTreeView Items="Items" ItemTemplate="MudTreeRoot.ItemTemplate" Class="mud-treeview-group">
                        @ChildContent
                    </MudTreeView>
                </CascadingValue>
            </CascadingValue>
        </MudCollapse>
    }
</li>